package com.yq.cp.service.basics.impl;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yq.cp.entity.basics.OrganizationalStructure;
import com.yq.cp.entity.basics.SecureTrainingRecords;
import com.yq.cp.mapper.basics.OrganizationalStructureMapper;
import com.yq.cp.mapper.basics.SecureTrainingRecordsMapper;
import com.yq.cp.service.basics.SecureTrainingRecordsService;
import com.yq.cp.utils.ExcelUtil;
import com.yq.cp.utils.TemplateExcelUtils;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 安全培训记录管理 服务实现类
 * </p>
 *
 * @author shenyuqing
 * @since 2024-09-03
 */
@Service
public class SecureTrainingRecordsServiceImpl extends ServiceImpl<SecureTrainingRecordsMapper, SecureTrainingRecords> implements SecureTrainingRecordsService {
    @Resource
    SecureTrainingRecordsMapper secureTrainingRecordsMapper;
    @Resource
    OrganizationalStructureMapper organizationalStructureMapper;
    @Override
    public void exportExcel(Long id, HttpServletResponse response) throws Exception {
        SecureTrainingRecords byId = secureTrainingRecordsMapper.selectById(id);
        OrganizationalStructure organizationalStructure = organizationalStructureMapper.selectById(byId.getSiteId());
        byId.setSiteName(organizationalStructure.getName());
        HashMap<String, Object> map = new HashMap<>();
        map.put("site",byId.getSiteName());
        map.put("address",byId.getAddress());
        map.put("department",byId.getDepartmentName());
        map.put("teacher",byId.getTeacherName());
        map.put("title",byId.getTitle());
        map.put("mude",byId.getObjective());
        map.put("content",byId.getContent());
        map.put("notes",byId.getNotes());
        String method = byId.getMethod();
        if (!method.contains("1"))
            map.put("kuang1","□");
        else
            map.put("kuang1","☑");
        if (!method.contains("2"))
            map.put("kuang2","□");
        else
            map.put("kuang2","☑");
        if (!method.contains("3"))
            map.put("kuang3","□");
        else
            map.put("kuang3","☑");
        if (!method.contains("4"))
            map.put("kuang4","□");
        else
            map.put("kuang4","☑");
        //exportFileByTemplate("templates/excel.xlsx","",map);
        //ExcelExportUtil.exportExcel("templates/word.docx",map);
        TemplateExcelUtils.downLoadExcel("安全培训表","excel.xlsx",map,response);
    }


}
